<?php
namespace Common\Models;
use Common\BaseModel;
class Category extends BaseModel
{
    public $res;
    public $redis_key = "index_category";
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_categories');
    }

    //获取所有分类
    public function get_all($parent_id)
    {
        $condition["columns"]    = "id,name,value as category_id,site,image";
        $condition['conditions'] = "parent_id = $parent_id";
        $res                     = $this->find($condition)->toarray();
        return $res;
    }

    //获取分类名称
    public function get_all_name($columns = '*')
    {
        $condition["columns"]    = $columns;
        $res                     = $this->find($condition);
        if ($res) {
            $res = $res->toarray();
        } else {
            $res = [];
        }
        return $res;
    }
}
